//管理数据的文件
import handleNum from "./index"

//其他页面调用dispatch时就会执行下面code
let reducer = (state = {...handleNum.state}, action: {type:string,val:number}) => {
    //实现对象深拷贝
    let newState = JSON.parse(JSON.stringify(state))
    // switch (action.type) {
    //     case handleNum.add1:
    //         handleNum.actions[handleNum.add1](newState, action)
    //         break;
    //     case handleNum.add2:
    //     handleNum.actions[handleNum.add2](newState, action)
    //         break;
    //     default:
    //         break;

    // }
    for(let key in handleNum.actionNames){
        if(action.type === handleNum.actionNames[key]){
            handleNum.actions[handleNum.actionNames[key]](newState, action)
            break
        }
    }
    return newState
}

export default reducer